home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C14 / Combined.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  594 b   |  38 lines

  1. //: C14:Combined.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Inheritance & composition
  7.  
  8. class A {
  9.   int i;
  10. public:
  11.   A(int ii) : i(ii) {}
  12.   ~A() {}
  13.   void f() const {}
  14. };
  15.  
  16. class B {
  17.   int i;
  18. public:
  19.   B(int ii) : i(ii) {}
  20.   ~B() {}
  21.   void f() const {}
  22. };
  23.  
  24. class C : public B {
  25.   A a;
  26. public:
  27.   C(int ii) : B(ii), a(ii) {}
  28.   ~C() {} // Calls ~A() and ~B()
  29.   void f() const {  // Redefinition
  30.     a.f();
  31.     B::f();
  32.   }
  33. };
  34.  
  35. int main() {
  36.   C c(47);
  37. } ///:~
  38.